using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using BL;
using BO;
using Telerik.WinControls.UI;
namespace AnimalFarm.Vet_manage
{
    public partial class UpdateVet : Telerik.WinControls.UI.RadForm
    {
        B_Vet vetManager;
        DataTable vetData;
        Vet_Info selectedVet;
        public UpdateVet()
        {
            InitializeComponent();
            vetManager = B_Vet.CreateInstance();
            bindVetData();

        }
        public void bindVetData()
        {
           vetData=vetManager.GetAllVet();
           radGridView1.DataSource = vetData;

        }
        public Vet_Info convertGridRowToVet(Telerik.WinControls.UI.GridViewRowInfo row)
        {
            Vet_Info vet = new Vet_Info();
            vet.VetID = int.Parse( row.Cells["VetID"].Value.ToString());
            vet.MAFFLicenceID =row.Cells["MAFFLicenceID"].Value.ToString();
            vet.PhoneNumber =row.Cells["PhoneNumber"].Value.ToString();
            vet.Address = row.Cells["Address"].Value.ToString();
            vet.DOB = (DateTime)row.Cells["DOB"].Value;
            vet.VetName = row.Cells["VetName"].Value.ToString();
            vet.UserName = row.Cells["UserName"].Value.ToString();
            vet.Password = row.Cells["Password"].Value.ToString();

            return vet;
        }
        private void radGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            if (radGridView1.SelectedRows.Count > 0)
            {
                GridViewRowInfo row = radGridView1.SelectedRows[0];
                this.selectedVet = convertGridRowToVet(row);
                showSelectedVetDetail();
            }
        }
        public void showSelectedVetDetail()
        {
            cm_mafffId.SelectedValue = selectedVet.MAFFLicenceID;
            txt_username.Text = selectedVet.UserName;
            txt_pass.Text = selectedVet.Password;
            txt_phone.Text = selectedVet.PhoneNumber;
            txtName.Text = selectedVet.VetName;
            txt_address.Text = selectedVet.Address;
            dtpTime.Value = selectedVet.DOB;
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            try
            {
                selectedVet.Address = txt_address.Text;
                selectedVet.DOB = dtpTime.Value;
                selectedVet.Password = txt_pass.Text;
                selectedVet.PhoneNumber = txt_phone.Text;
                selectedVet.VetName = txtName.Text;
                selectedVet.UserName = txtName.Text;
                selectedVet.MAFFLicenceID = cm_mafffId.SelectedText;
                bool ok = vetManager.EditOneVet(selectedVet);
                if (ok)
                    MessageBox.Show("Updated");
                else
                    MessageBox.Show("Update fail");
            }
            catch (Exception er)
            { }
        }

        private void radGridView1_Click(object sender, EventArgs e)
        {

        }
    }
}
